package com.ruoyi.web.wuliu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.web.wuliu.domain.MaterialCarVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.wuliu.domain.MaterialMessage;
import com.ruoyi.web.wuliu.service.IMaterialMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物流信息Controller
 * 
 * @author ruoyi
 * @date 2023-11-15
 */
@RestController
@RequestMapping("/wuliu/message")
public class MaterialMessageController extends BaseController
{
    @Autowired
    private IMaterialMessageService materialMessageService;

    /**
     * 查询物流信息列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialMessage materialMessage)
    {
        startPage();
        List<MaterialMessage> list = materialMessageService.selectMaterialMessageList(materialMessage);
        return getDataTable(list);
    }

    /**
     * 导出物流信息列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:message:export')")
    @Log(title = "物流信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialMessage materialMessage)
    {
        List<MaterialMessage> list = materialMessageService.selectMaterialMessageList(materialMessage);
        ExcelUtil<MaterialMessage> util = new ExcelUtil<MaterialMessage>(MaterialMessage.class);
        util.exportExcel(response, list, "物流信息数据");
    }

    /**
     * 获取物流信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(materialMessageService.selectMaterialMessageById(id));
    }

    /**
     * 新增物流信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:message:add')")
    @Log(title = "物流信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialMessage materialMessage)
    {
        return toAjax(materialMessageService.insertMaterialMessage(materialMessage));
    }

    /**
     * 修改物流信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:message:edit')")
    @Log(title = "物流信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialMessage materialMessage)
    {
        return toAjax(materialMessageService.updateMaterialMessage(materialMessage));
    }

    /**
     * 删除物流信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:message:remove')")
    @Log(title = "物流信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(materialMessageService.deleteMaterialMessageByIds(ids));
    }

    @GetMapping("/getOrderUser/{id}")
    public AjaxResult getOrderUser(@PathVariable String id)
    {
        List<MaterialCarVo> list = materialMessageService.getUserOrder(id);
        return AjaxResult.success(list);
    }
}
